package com.dx.mes.service.process.service;

import static com.dx.mes.common.bean.def.GenericDef.PROC_EMPTY;
import static com.dx.mes.common.bean.def.GenericDef.RETURN_CODE_OK;
import static com.dx.mes.common.bean.def.GenericDef.RETURN_CODE_SET_ERROR;
import static com.dx.mes.common.bean.def.GenericDef.RETURN_CODE_UNKNOWN;
import static com.dx.mes.common.bean.def.GenericDef.RETURN_MESG_OK;
import static com.dx.mes.common.bean.def.GenericDef.TRX_OUT;
import static com.dx.mes.common.bean.def.GenericDef.T_FSPBOXCHGDEF;
import static com.dx.mes.common.bean.def.GenericDef._NORMAL;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;

import com.dx.mes.facade.process.tx.Fspboxchgdef.*;

import org.apache.commons.lang.StringUtils;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRichTextString;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.hibernate.Session;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.interceptor.TransactionAspectSupport;

import com.dx.common.table.ppt.Ret_box;
import com.dx.common.table.ppt.Ret_box_chg_def;
import com.dx.common.table.ppt.Ret_prd_info;
import com.dx.mes.common.dao.IRetBoxChgDefDao;
import com.dx.mes.common.dao.IRetBoxDao;
import com.dx.mes.common.dao.IRetPrdInfoDao;
import com.dx.mes.common.table.rtnBean.SimpleRtnBeen;
import com.dx.mes.common.transcoder.util.AppContext;
import com.dx.mes.common.transcoder.util.GUIDGenerator;
import com.dx.mes.common.transcoder.util.JacksonUtil;
import com.dx.mes.common.transcoder.util.LogUtils;
import com.dx.mes.common.transcoder.util.Util;
import com.dx.mes.facade.process.service.IFspboxchgdefService;

@Service("fspboxchgdefService")
@SuppressWarnings({"unchecked"})
public class FspboxchgdefService implements IFspboxchgdefService{

	private static final String TX_NAME = T_FSPBOXCHGDEF;
	private LogUtils logUtils;

	@Autowired
	private IRetBoxChgDefDao retBoxChgDefDao;
	
	@Autowired
	private IRetPrdInfoDao retPrdInfoDao;
	
	@Autowired
	private IRetBoxDao retBoxDao;
	
	public String subMainProc(String evt_no, String strInTrx) {
		AppContext.clear();
		AppContext.setCurrServiceName(FspboxchgdefService.class.getSimpleName());
		AppContext.setCurrEventNumber(evt_no);
		logUtils = new LogUtils(FspboxchgdefService.class);
		logUtils.info("[InTrx:" + strInTrx + "]");
		
		Session session = retBoxChgDefDao.getCrSession();
		FspboxchgdefO outTrx = new FspboxchgdefO();
		String strOutTrx = null;
		
		outTrx.setTrx_id(TX_NAME);
		outTrx.setType_id(TRX_OUT);
		outTrx.setRtn_code(String.valueOf(RETURN_CODE_SET_ERROR));
		
		//输入对象
		try {
			FspboxchgdefI inTrx = new FspboxchgdefI();
		//将json字符串转换成对象
		inTrx = JacksonUtil.fromJson(strInTrx, FspboxchgdefI.class);
		char action_flg = inTrx.getAction_flg().charAt(0);
		
		switch (action_flg) {
			case 'Q':
				queryChgDefFnc(inTrx,outTrx);
				break;
			case  'S':
				saveFnc(inTrx,outTrx);
				break;
			case 'R':
				registerFnc(inTrx,outTrx);
				break;
			case 'G':
				generateExcel(inTrx,outTrx);
				break;
			/*case 'I':
				importExcel(inTrx,outTrx);
				break;*/
			case 'D':
				deleteFnc(inTrx,outTrx);
				break;
			default:
				errActionFnc(outTrx);
			}
			if (RETURN_CODE_OK.equals(outTrx.getRtn_code())) {
				session.flush();
			} else {
				TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
			}
		}catch (Exception ex) {
			outTrx.setRtn_code(RETURN_CODE_UNKNOWN);
			outTrx.setRtn_mesg(ex.toString());
			TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
		} finally {
			//将一个 Object 或者List对象转化为JSOObject或者JSONArray
			strOutTrx = JacksonUtil.toJSONStr(outTrx);
			logUtils.info("[OutTrx:" + strOutTrx + "]");
		}
		return strOutTrx;
	}
	
	public void queryChgDefFnc(FspboxchgdefI inTrx,FspboxchgdefO outTrx){
			List<FspboxchgdefIA> iaryList = inTrx.getIary();
			FspboxchgdefIA iary = iaryList.get(0);
			FspboxchgdefIB iaryB = inTrx.getIaryB().get(0);
			String boxIdFkA = iary.getBox_Id_FkA();
			String boxIdFkB = iaryB.getBox_Id_FkB();
			/*if(StringUtils.isEmpty(boxIdFkA) && StringUtils.isEmpty(boxIdFkB)){
				outTrx.setRtn_code(RETURN_CODE_UNKNOWN);
				outTrx.setRtn_mesg("源箱号和目标箱号都为空，请输入！");
				return;
			}*/
			String hql = "FROM Ret_box_chg_def where 1 = 1";
			if(!StringUtils.isEmpty(boxIdFkA)){
				hql = hql + " and fr_box_id_fk = '" + boxIdFkA + "'";
			}
			if(!StringUtils.isEmpty(boxIdFkB)){
				hql = hql + " and to_box_id_fk = '" + boxIdFkB + "'"; 
			}
			List<Ret_box_chg_def> ret_box_chg_defs= retBoxChgDefDao.find(hql);
			List<FspboxchgdefOA> oaryList = new ArrayList<FspboxchgdefOA>();
			for (Ret_box_chg_def ret_box_chg_def : ret_box_chg_defs) {
				FspboxchgdefOA oary = new FspboxchgdefOA();
				oary.setBox_chg_seq_id(ret_box_chg_def.getBox_chg_seq_id());
				oary.setFr_slot_no_fk(ret_box_chg_def.getFr_slot_no_fk());
				oary.setFr_box_id_fk(ret_box_chg_def.getFr_box_id_fk());
				oary.setTo_slot_no_fk(ret_box_chg_def.getTo_slot_no_fk());
				oary.setTo_box_id_fk(ret_box_chg_def.getTo_box_id_fk());
				oary.setEvt_usr(ret_box_chg_def.getEvt_usr());
				oary.setEvt_timestamp(ret_box_chg_def.getEvt_timestamp().toString());
				oary.setEvt_note(ret_box_chg_def.getEvt_note());
				oaryList.add(oary);
			}
			outTrx.setOary(oaryList);
			outTrx.setRtn_code(RETURN_CODE_OK);
			outTrx.setRtn_mesg(RETURN_MESG_OK);
	}
	
	//等级导入模板后的
	public void registerFnc(FspboxchgdefI inTrx,FspboxchgdefO outTrx){
		SimpleRtnBeen rtnBeen = new SimpleRtnBeen(_NORMAL);
		long lRc = _NORMAL;
		String gszMsgBuf = "";
		List<FspboxchgdefIA> iaryList = inTrx.getIary();
		String evtNote = inTrx.getEvt_note();
		String evtUsr = inTrx.getEvt_usr();
		Timestamp currentTime = Util.getCurrentTimestamp();
		if(!iaryList.isEmpty()){
			for (FspboxchgdefIA iary : iaryList) {
				String evtSeqId = GUIDGenerator.javaGUID();
				//String prd_seq_id = iary.getPrd_seq_id();
				String fr_box_id_fk = iary.getFr_box_id_fk();
				String fr_slot_no_fk = iary.getFr_slot_no_fk();
				String to_box_id_fk = iary.getTo_box_id_fk();
				String to_slot_no_fk = iary.getTo_slot_no_fk();

				rtnBeen = checkRetBoxChgDef(fr_box_id_fk, fr_slot_no_fk, to_box_id_fk, to_slot_no_fk);
				if (_NORMAL != rtnBeen.getlRc()) {
					gszMsgBuf = rtnBeen.getMsgBuf();
					outTrx.setRtn_code(RETURN_CODE_UNKNOWN);
					outTrx.setRtn_mesg(gszMsgBuf);
					return;
				}

				//7.	导入方式需检查子格位设定跟模板的关系，模板格式见1.2.1；
				//8.	操作人和时间默认都记录
				Ret_box_chg_def retBoxChgDef = new Ret_box_chg_def();
				retBoxChgDef.setFr_box_id_fk(fr_box_id_fk);
				retBoxChgDef.setFr_slot_no_fk(fr_slot_no_fk);
				//通过转入查到该prd_seq_id;
				String hql = "From Ret_prd_info where box_id_fk = '"+fr_box_id_fk
						+ "' and slot_no ='" + fr_slot_no_fk +"'";
				List<Ret_prd_info>  ret_prd_infos= retPrdInfoDao.find(hql);
				String prdSeqId = ret_prd_infos.get(0).getPrd_seq_id();
				retBoxChgDef.setTo_box_id_fk(to_box_id_fk);
				retBoxChgDef.setTo_slot_no_fk(to_slot_no_fk);
				retBoxChgDef.setEvt_note(evtNote);
				retBoxChgDef.setEvt_usr(evtUsr);
				retBoxChgDef.setEvt_timestamp(currentTime);
				retBoxChgDef.setPrd_seq_id_fk(prdSeqId);//设定后玻璃
				//retBoxChgDef.setEvt_cate(evt_cate);
				retBoxChgDef.setBox_chg_seq_id(evtSeqId);
				retBoxChgDefDao.save(retBoxChgDef);
			}
		}else{
			outTrx.setRtn_code(RETURN_CODE_UNKNOWN);
			outTrx.setRtn_mesg("列表为空，请重新确认后登记!");
			return;
		}
		outTrx.setRtn_code(RETURN_CODE_OK);
		outTrx.setRtn_mesg(RETURN_MESG_OK);
	}
	//保存手动修改后的
	public void saveFnc(FspboxchgdefI inTrx,FspboxchgdefO outTrx){
			SimpleRtnBeen rtnBeen = new SimpleRtnBeen(_NORMAL);
			long lRc = _NORMAL;
			String gszMsgBuf = "";
			List<FspboxchgdefIA> iaryList = inTrx.getIary();
			List<FspboxchgdefIB> iaryBList = inTrx.getIaryB();
			if(iaryList.isEmpty() && iaryBList.isEmpty()){
				outTrx.setRtn_code(RETURN_CODE_UNKNOWN);
				outTrx.setRtn_mesg("取样模板列表为空，请重新确认后保存!");
				return;
			}
			String evtNote = inTrx.getEvt_note();
			String evtUsr = inTrx.getEvt_usr();
			Timestamp currentTime = Util.getCurrentTimestamp();
			//判断A箱、B箱制程
			checkABNext(inTrx,outTrx);
			//A箱
			if(!iaryList.isEmpty()){
				for (FspboxchgdefIA iary : iaryList) {
					String evtSeqId = GUIDGenerator.javaGUID();
					String prd_seq_id = iary.getPrd_seq_id();
					String fr_box_id_fk = iary.getFr_box_id_fk();
					String fr_slot_no_fk = iary.getFr_slot_no_fk();
					String to_box_id_fk = iary.getTo_box_id_fk();
					String to_slot_no_fk = iary.getTo_slot_no_fk();
					
					rtnBeen = checkRetBoxChgDef(fr_box_id_fk, fr_slot_no_fk, to_box_id_fk, to_slot_no_fk);
					if (_NORMAL != rtnBeen.getlRc()) {
						gszMsgBuf = rtnBeen.getMsgBuf();
						outTrx.setRtn_code(RETURN_CODE_UNKNOWN);
						outTrx.setRtn_mesg(gszMsgBuf);
						return;
					}
					
					//7.	导入方式需检查子格位设定跟模板的关系，模板格式见1.2.1；
					//8.	操作人和时间默认都记录
					Ret_box_chg_def retBoxChgDef = new Ret_box_chg_def();
					retBoxChgDef.setFr_box_id_fk(fr_box_id_fk);
					retBoxChgDef.setFr_slot_no_fk(fr_slot_no_fk);
					retBoxChgDef.setTo_box_id_fk(to_box_id_fk);
					retBoxChgDef.setTo_slot_no_fk(to_slot_no_fk);
					retBoxChgDef.setEvt_note(evtNote);
					retBoxChgDef.setEvt_usr(evtUsr);
					retBoxChgDef.setEvt_timestamp(currentTime);
					retBoxChgDef.setPrd_seq_id_fk(prd_seq_id);//设定后玻璃
					//retBoxChgDef.setEvt_cate(evt_cate);
					retBoxChgDef.setBox_chg_seq_id(evtSeqId);
					retBoxChgDefDao.save(retBoxChgDef);
				}
			}
			
			if(!iaryBList.isEmpty()){
				for (FspboxchgdefIB iaryB : iaryBList) {
					String   evtSeqId = GUIDGenerator.javaGUID();
					String prd_seq_id = iaryB.getPrd_seq_id();
					String fr_box_id_fk = iaryB.getFr_box_id_fk();
					String fr_slot_no_fk = iaryB.getFr_slot_no_fk();
					String to_box_id_fk = iaryB.getTo_box_id_fk();
					String to_slot_no_fk = iaryB.getTo_slot_no_fk();
					
					rtnBeen = checkRetBoxChgDef(fr_box_id_fk, fr_slot_no_fk, to_box_id_fk, to_slot_no_fk);
					if (_NORMAL != rtnBeen.getlRc()) {
						gszMsgBuf = rtnBeen.getMsgBuf();
						outTrx.setRtn_code(RETURN_CODE_UNKNOWN);
						outTrx.setRtn_mesg(gszMsgBuf);
						return;
					}
					//7.	导入方式需检查子格位设定跟模板的关系，模板格式见1.2.1；
					//8.	操作人和时间默认都记录
					Ret_box_chg_def retBoxChgDef = new Ret_box_chg_def();
					retBoxChgDef.setFr_box_id_fk(fr_box_id_fk);
					retBoxChgDef.setFr_slot_no_fk(fr_slot_no_fk);
					retBoxChgDef.setTo_box_id_fk(to_box_id_fk);
					retBoxChgDef.setTo_slot_no_fk(to_slot_no_fk);
					retBoxChgDef.setEvt_note(evtNote);
					retBoxChgDef.setEvt_usr(evtUsr);
					retBoxChgDef.setEvt_timestamp(currentTime);
					retBoxChgDef.setPrd_seq_id_fk(prd_seq_id);//设定后玻璃
					//retBoxChgDef.setEvt_cate(evt_cate);
					retBoxChgDef.setBox_chg_seq_id(evtSeqId);
					retBoxChgDefDao.save(retBoxChgDef);
				}
			}
			
			outTrx.setRtn_code(RETURN_CODE_OK);
			outTrx.setRtn_mesg(RETURN_MESG_OK);
	}
	
	public SimpleRtnBeen checkRetBoxChgDef(String fr_box_id_fk,String fr_slot_no_fk,
			String to_box_id_fk,String to_slot_no_fk){
		String gszMsgBuf = "";
		String hql = "FROM Ret_box_chg_def where 1=1";
		if(!Util.isSpaceCheck(fr_box_id_fk)){
			hql = hql + " and fr_box_id_fk = '" +fr_box_id_fk +"'";
		}
		if(!Util.isSpaceCheck(fr_slot_no_fk)){
			hql = hql + " and fr_slot_no_fk = '" + fr_slot_no_fk+"'";
		}
		List<Ret_box_chg_def> ret_box_chg_defs = retBoxChgDefDao.find(hql);
		if(!ret_box_chg_defs.isEmpty()){
			gszMsgBuf = "源箱号["+fr_box_id_fk+"]与源子格位["+fr_slot_no_fk+"]已存在，请重新设置！";
			return new SimpleRtnBeen(Long.parseLong(RETURN_CODE_UNKNOWN), gszMsgBuf);
		}
		//判断源箱子格位是否有玻璃
		String hql2 = "From Ret_prd_info where 1 = 1";
		hql2 = hql2 + " and box_id_fk = '"+ fr_box_id_fk +"'" +" and slot_no ='"+ fr_slot_no_fk +"'";
		List<Ret_prd_info> ret_prd_infos = retPrdInfoDao.find(hql2);
		if(ret_prd_infos.isEmpty()){
			gszMsgBuf = "源箱号["+fr_box_id_fk+"]与源子格位["+fr_slot_no_fk+"]中不存在产品，请重新设置！";
			return new SimpleRtnBeen(Long.parseLong(RETURN_CODE_UNKNOWN), gszMsgBuf);
		}
		
		String hql3 = "FROM Ret_box_chg_def where 1=1";
		if(!Util.isSpaceCheck(to_box_id_fk)){
			hql3 = hql3 + " and to_box_id_fk = '" +to_box_id_fk +"'";
		}
		if(!Util.isSpaceCheck(to_slot_no_fk)){
			hql3 = hql3 + " and to_slot_no_fk = '" + to_slot_no_fk+"'";
		}
		List<Ret_box_chg_def> ret_box_chg_defs2 = retBoxChgDefDao.find(hql3);
		if(!ret_box_chg_defs2.isEmpty()){
			gszMsgBuf = "目标箱号["+fr_box_id_fk+"]与目标格位["+fr_slot_no_fk+"]已存在，请重新设置！";
			return new SimpleRtnBeen(Long.parseLong(RETURN_CODE_UNKNOWN), gszMsgBuf);
		}
		
		//判断目标箱子格位是否有玻璃 ,没有就执行
		String hql4 = "From Ret_prd_info where 1 = 1";
		hql4 = hql4 + " and box_id_fk = '"+ to_box_id_fk +"'" +" and slot_no ='"+ to_slot_no_fk +"'";
		List<Ret_prd_info> ret_prd_infos2 = retPrdInfoDao.find(hql4);
		if(ret_prd_infos2.isEmpty()){
			;
		}else {
				gszMsgBuf = "目标箱号["+fr_box_id_fk+"]与目标子格位["+fr_slot_no_fk+"]中存在产品，请重新设置！";
				return new SimpleRtnBeen(Long.parseLong(RETURN_CODE_UNKNOWN), gszMsgBuf);
		}
		
		return new SimpleRtnBeen(_NORMAL);
	}
	
	//9.若A，B均有产品，需检查下一站是否一致，工艺路线是否一致；
	public void checkABNext(FspboxchgdefI inTrx,FspboxchgdefO outTrx){
		String boxIdA = inTrx.getBox_idA();
		String boxIdB = inTrx.getBox_idB();
		Ret_box ret_boxA = retBoxDao.get(boxIdA);
		Ret_box ret_boxB = retBoxDao.get(boxIdB);
		if(!PROC_EMPTY.equals(ret_boxA.getBox_stat())
				&&!PROC_EMPTY.equals(ret_boxB.getBox_stat())){
			if(!ret_boxA.getNx_ope_id_fk().equals(ret_boxB.getNx_ope_id_fk())){
				outTrx.setRtn_code(RETURN_CODE_UNKNOWN);
				outTrx.setRtn_mesg("A箱 ["+boxIdA+"]的下一站点["+ret_boxA.getNx_ope_id_fk()
				+"]与B箱["+boxIdB+"]的下一站点["+ret_boxB.getNx_ope_id_fk()+"]不符，请重新设置！");
				return;
			}
			
			if(!ret_boxA.getNx_path_id_fk().equals(ret_boxB.getNx_path_id_fk())){
				outTrx.setRtn_code(RETURN_CODE_UNKNOWN);
				outTrx.setRtn_mesg("A箱 ["+boxIdA+"]的下一工艺路线["+ret_boxA.getNx_path_id_fk()
				+"]与B箱["+boxIdB+"]的下一工艺路线["+ret_boxB.getNx_path_id_fk()+"]不符，请重新设置！");
				return;
			}
		}
	}

	public HSSFWorkbook  generateEx(List<SortPo> list){
		//创建HSSFWorkbook对象(excel的文档对象)
		HSSFWorkbook wkb = new HSSFWorkbook();
		//建立新的sheet对象（excel的表单）
		HSSFSheet sheet=wkb.createSheet("Sorter");
		//在sheet里创建第一行，参数为行索引(excel的行)，可以是0～65535之间的任何一个
		HSSFRow row1=sheet.createRow(0);
		//创建单元格（excel的单元格，参数为列索引，可以是0～255之间的任何一个
		HSSFCell cell=row1.createCell((short)0);
		//设置单元格内容
		cell.setCellValue(new HSSFRichTextString("源箱号"));
		HSSFCell cell2 =row1.createCell((short)1);
		cell2.setCellValue(new HSSFRichTextString("源子格位"));
		HSSFCell cell3 =row1.createCell((short)2);
		cell3.setCellValue(new HSSFRichTextString("目标箱号"));
		HSSFCell cell4 =row1.createCell((short)3);
		cell4.setCellValue(new HSSFRichTextString("目标子格位"));
		HSSFCell cell5 =row1.createCell((short)4);
		cell5.setCellValue(new HSSFRichTextString("备注"));

		for(int i = 1 ; i < list.size() + 1;i++){
			SortPo SortPo = list.get(i-1);
			HSSFRow row2=sheet.createRow(i);
			row2.createCell((short)0).setCellValue(new HSSFRichTextString(SortPo.getFr_box_id_fk()));
			row2.createCell((short)1).setCellValue(new HSSFRichTextString(SortPo.getFr_slot_no_fk()));
			row2.createCell((short)2).setCellValue(new HSSFRichTextString(SortPo.getTo_box_id_fk()));
			row2.createCell((short)3).setCellValue(new HSSFRichTextString(SortPo.getTo_slot_no_fk()));
			row2.createCell((short)4).setCellValue(new HSSFRichTextString(SortPo.getEvtNote()));
		}
		return wkb;
	}


	//导出
	public void generateExcel(FspboxchgdefI inTrx,FspboxchgdefO outTrx){
		String evtNote = inTrx.getEvt_note();
		List<FspboxchgdefIA> iaryList = inTrx.getIary();
		
		//创建HSSFWorkbook对象(excel的文档对象)  
		 HSSFWorkbook wkb = new HSSFWorkbook();
		//建立新的sheet对象（excel的表单）  
		 HSSFSheet sheet=wkb.createSheet("Sorter");
		//在sheet里创建第一行，参数为行索引(excel的行)，可以是0～65535之间的任何一个  
		 HSSFRow row1=sheet.createRow(0);  
		 //创建单元格（excel的单元格，参数为列索引，可以是0～255之间的任何一个  
		 HSSFCell cell=row1.createCell((short)0);  
		 //设置单元格内容  
		 cell.setCellValue(new HSSFRichTextString("源箱号")); 
		 HSSFCell cell2 =row1.createCell((short)1); 
		 cell2.setCellValue(new HSSFRichTextString("源子格位")); 
		 HSSFCell cell3 =row1.createCell((short)2); 
		 cell3.setCellValue(new HSSFRichTextString("目标箱号"));
		 HSSFCell cell4 =row1.createCell((short)3); 
		 cell4.setCellValue(new HSSFRichTextString("目标子格位"));
		 HSSFCell cell5 =row1.createCell((short)4); 
		 cell5.setCellValue(new HSSFRichTextString("备注"));
		 
		 //第二行开始填充数据
		 for(int i = 1 ; i < iaryList.size() + 1;i++){
			 FspboxchgdefIA iary = iaryList.get(i-1);
			 HSSFRow row2=sheet.createRow(i);
			 row2.createCell((short)0).setCellValue(new HSSFRichTextString(iary.getFr_box_id_fk()));
			 row2.createCell((short)1).setCellValue(new HSSFRichTextString(iary.getFr_slot_no_fk()));
			 row2.createCell((short)2).setCellValue(new HSSFRichTextString(iary.getTo_box_id_fk()));
			 row2.createCell((short)3).setCellValue(new HSSFRichTextString(iary.getTo_slot_no_fk()));
			 row2.createCell((short)4).setCellValue(new HSSFRichTextString(evtNote));
		 }
		
		//输出Excel文件  
		FileOutputStream output;
		String filename = String.valueOf(System.currentTimeMillis());
		try {
		    File file = new File("E://Excel");
		    if(!file.exists()){
		        file.mkdir();
            }

			File file2 = new File("E://Excel"+"/"+filename+".xls");
			if(!file2.exists())
			{
			    try {
			        file2.createNewFile();
			    } catch (IOException e) {
			        e.printStackTrace();
			    }
			}
			output = new FileOutputStream(file2);
			wkb.write(output);
			output.flush();
		} catch (FileNotFoundException e1) {
			e1.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		outTrx.setRtn_code(RETURN_CODE_OK);
		outTrx.setRtn_mesg(RETURN_MESG_OK);
		return;
	}
	
/*	//导入Excel并登记到数据库
	public void importExcel(FspboxchgdefI inTrx,FspboxchgdefO outTrx){
		
	}*/
	
	
	public void deleteFnc(FspboxchgdefI inTrx,FspboxchgdefO outTrx){
		List<FspboxchgdefIA> iaryList = inTrx.getIary();
		for (FspboxchgdefIA iary : iaryList) {
			String boxChgSeqId = iary.getBox_chg_seq_id();
			Ret_box_chg_def ret_box_chg_def = retBoxChgDefDao.get(boxChgSeqId);
			if(ret_box_chg_def!=null){
				retBoxChgDefDao.delete(ret_box_chg_def);
			}
		}
		outTrx.setRtn_code(RETURN_CODE_OK);
		outTrx.setRtn_mesg(RETURN_MESG_OK);
	}
	
	//错误信息
	public void errActionFnc(FspboxchgdefO outTrx) {
		outTrx.setRtn_code("0000009");
		outTrx.setRtn_mesg("Invalid Action_flg");
	}

}
